package cn.tedu.ivos2.dict.controller;

import cn.tedu.ivos2.base.response.JsonResult;
import cn.tedu.ivos2.dict.pojo.dto.DictQuery;
import cn.tedu.ivos2.dict.pojo.dto.DictSaveDTO;
import cn.tedu.ivos2.dict.pojo.vo.DictVO;
import cn.tedu.ivos2.dict.service.DictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/dict/")
public class DictController {
    @Autowired
    private DictService dictService;

    @GetMapping("select")
    public JsonResult selectDic(DictQuery dictQuery){
        log.debug("C1-查询字典内容:{}",dictQuery);
        List<DictVO>dictList= dictService.selectDic(dictQuery);
        log.debug("C2-查询结果:{}",dictList);
        return JsonResult.ok(dictList);
    }

    @PostMapping("save")
    public JsonResult saveDict(DictSaveDTO dictSaveDTO){
        log.debug("保存字典数据:{}",dictSaveDTO);
        dictService.saveDict(dictSaveDTO);
        return JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    public JsonResult deleteDic(@PathVariable Long id){
        log.debug("删除的字典id{}",id);
        dictService.deleteDic(id);
        return JsonResult.ok();
    }
}
